#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <vector>
#define ll long long
using namespace std;
#ifdef ONLINE_JUDGE

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf;

#endif
int read() {
	int p = 0, flg = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') flg = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		p = p * 10 + c - '0';
		c = getchar();
	}
	return p * flg;
}
void write(ll x) {
	if (x < 0) {
		x = -x;
		putchar('-');
	}
	if (x > 9) {
		write(x / 10);
	}
	putchar(x % 10 + '0');
}
bool _stmer;

const int N = 5e5 + 5;

namespace Sgt {

array <ll, N * 4> edge;

void modify(int x, int l, int r, int k, ll y) {
	if (l == r) {
		edge[x] = y;
		return;
	}
	int mid = (l + r) >> 1;
	if (k <= mid) modify(x * 2, l, mid, k, y);
	else modify(x * 2 + 1, mid + 1, r, k, y);
	edge[x] = min(edge[x * 2], edge[x * 2 + 1]);
}

ll query(int x, int l, int r, int L, int R) {
	if (L > r || R < l) return 1e18;
	if (L <= l && R >= r) return edge[x];
	ll mid = (l + r) >> 1, ans = 1e18;
	if (L <= mid) ans = min(ans, query(x * 2, l, mid, L, R));
	if (R > mid) ans = min(ans, query(x * 2 + 1, mid + 1, r, L, R));
	return ans;
}

} //namespace Sgt

array <int, N> s;

array <ll, N> f;
array <vector <int>, N> qrl;

bool _edmer;
int main() {
	cerr << (&_stmer - &_edmer) / 1024.0 / 1024.0 << "MB\n";
#ifndef cxqghzj
	freopen("gonna.in", "r", stdin);
	freopen("gonna.out", "w", stdout);
#endif
	int n = read();
	for (int i = 1; i <= n; i++) s[i] = read();
	int m = read();
	for (int i = 1, x, y; i <= m; i++)
		x = read(), y = read(), qrl[y].push_back(x);
	int pos = 0;
	Sgt::modify(1, 0, n, 0, 0);
	for (int i = 1; i <= n; i++) {
		for (auto k : qrl[i - 1])
			pos = max(pos, k);
		f[i] = Sgt::query(1, 0, n, pos, i - 1) + s[i];
		Sgt::modify(1, 0, n, i, f[i]);
	}
	for (auto k : qrl[n]) pos = max(pos, k);
	ll ans = 1e18;
	for (int i = pos; i <= n; i++)
		ans = min(ans, f[i]);
	//cerr << endl;
	write(ans), puts("");
	return 0;
}
